package com.apartment.poi
        ;

import com.deepoove.poi.config.Configure;
import com.deepoove.poi.data.MiniTableRenderData;
import com.deepoove.poi.data.RowRenderData;
import com.deepoove.poi.policy.HackLoopTableRenderPolicy;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STHighlightColor.Enum;

import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.data.TextRenderData;
import com.deepoove.poi.data.style.Style;

import java.io.FileOutputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

import static javax.swing.UIManager.put;

/**
 * @program: apartment
 * @description:
 * @author: @Dog_E
 * @create: 2020-09-01 13:44
 **/
public class Testss {
    public Testss() {
    }

    public static Integer getI() {
        return i;
    }

    public static void setI(Integer i) {
        Testss.i = i;
    }

    static Integer i = 1;

    public static void main(String[] args) throws Exception {
        Style styles = new Style();


        HackLoopTableRenderPolicy policy = new HackLoopTableRenderPolicy();


        Configure config = Configure.newBuilder()
                .bind("goods", policy).build();

        XWPFTemplate template = XWPFTemplate.compile("C:/Users/Administrator/Desktop/代码生成/template.docx", config).render(
                new HashMap<String, Object>() {{
                    put("标题", "Easypoi");
                    put("person", "JueYueJueYueJueYueJueYueJueYueJueYueJueYueJueYueJueYueJueYueJueYueJueYueJueYueJueYueJueYueJueYueJueYueJueYueJueYueJueYueJueYueJueYueJueYueJueYueJueYueJueYueJueYueJueYueJueYueJueYueJueYueJueYueJueYueJueYueJueYueJueYueJueYueJueYueJueYueJueYueJueYueJueYue");
                    put("time", new Date());
                    put("title", "我是大标题");
                    List<Goods> goods1 = new ArrayList<Goods>();
                    List<Goods> goods2 = new ArrayList<Goods>();
                    for (int j = 0; j < 2; j++) {
                        Goods goods = new Goods(11);
                        goods2.add(goods);
                    }

                    for (int j = 0; j < 10; j++) {
                        Goods goods = new Goods();
                        goods.setCount(i++);
                        goods.setName("name  " + i);
                        goods.setDesc(i.toString());
                        goods.setDiscount(0);
                        goods.setTax(0);
                        goods.setPrice(0);
                        goods.setTotalPrice(0);
                        goods.setGoodsList(goods2);
                        goods1.add(goods);
                        System.out.println("goods = " + goods);
                    }
                    put("goods", goods1);
                }});

        FileOutputStream out = new FileOutputStream("C:/Users/Administrator/Desktop/代码生成/template2.docx");
        template.write(out);
        out.flush();
        out.close();
        template.close();
    }
}

class Goods {
    private int count;
    private String name;
    private String desc;
    private int discount;
    private int tax;
    private int price;
    private int totalPrice;
    private List<Goods> goodsList;
    // getter setter

    @Override
    public String toString() {
        return "Goods{" +
                "count=" + count +
                ", name='" + name + '\'' +
                ", desc='" + desc + '\'' +
                ", discount=" + discount +
                ", tax=" + tax +
                ", price=" + price +
                ", totalPrice=" + totalPrice +
                ", goodsList=" + goodsList +
                '}';
    }

    public Goods() {
    }

    public Goods(int price) {
        this.price = price;
    }

    public List<Goods> getGoodsList() {
        return goodsList;
    }

    public void setGoodsList(List<Goods> goodsList) {
        this.goodsList = goodsList;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public int getDiscount() {
        return discount;
    }

    public void setDiscount(int discount) {
        this.discount = discount;
    }

    public int getTax() {
        return tax;
    }

    public void setTax(int tax) {
        this.tax = tax;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public int getTotalPrice() {
        return totalPrice;
    }

    public void setTotalPrice(int totalPrice) {
        this.totalPrice = totalPrice;
    }

}

class Labor {
    private String category;
    private int people;
    private int price;
    private int totalPrice;
    // getter setter


    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public int getPeople() {
        return people;
    }

    public void setPeople(int people) {
        this.people = people;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public int getTotalPrice() {
        return totalPrice;
    }

    public void setTotalPrice(int totalPrice) {
        this.totalPrice = totalPrice;
    }
}

class AA {
    /**
     * @param stime:
     * @param etime:
     * @Description:
     * @return: java.util.List<java.lang.String>
     * @Author: @Dog_E
     * @Date: 2020/9/2 0002
     **/
    public static List<String> findDates(String stime, String etime)
            throws ParseException {
        List<String> allDate = new ArrayList();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        Date dBegin = sdf.parse(stime);
        Date dEnd = sdf.parse(etime);
        allDate.add(sdf.format(dBegin));
        Calendar calBegin = Calendar.getInstance();
        // 使用给定的 Date 设置此 Calendar 的时间
        calBegin.setTime(dBegin);
        Calendar calEnd = Calendar.getInstance();
        // 使用给定的 Date 设置此 Calendar 的时间
        calEnd.setTime(dEnd);
        // 测试此日期是否在指定日期之后
        while (dEnd.after(calBegin.getTime())) {
            // 根据日历的规则，为给定的日历字段添加或减去指定的时间量
            calBegin.add(Calendar.DAY_OF_MONTH, 1);
            allDate.add(sdf.format(calBegin.getTime()));
        }
        return allDate;
    }

    public static void main(String[] args) {
        //测试数据
        String stime = "2019-01-31";
        String etime = "2020-05-30";

        //集合中包含2019-05-01/2019-05-05，不需要可去除
        List<String> list = new ArrayList<String>();
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            long s = Long.valueOf(sdf.parse(stime).getTime());
            long e = Long.valueOf(sdf.parse(etime).getTime());
            //只有结束时间大于开始时间时才进行查询
            if (s < e) {
                list = findDates(stime, etime);
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        for (String time : list) {
            System.out.println(time);
        }
        System.out.println("间隔天数：" + list.size());
    }
}